import { Injectable } from '@angular/core';
import axios from 'axios';
import {BaseService} from '../config/base.service';

@Injectable({
  providedIn: 'root'
})
export class RequestService {

  public gateway;
  constructor() {
    this.gateway=(new BaseService()).gateway;
  }

  public postJSON (Url:String,Data:any){

    return new Promise((succ,error)=>{
      // @ts-ignore
      axios.post(this.gateway+Url,Data).then(e=>{

        if(e.data.err!=0){
          error(e.data);return;
        }
        succ(e.data);
      },(fail:any)=>{
        error({err:500,msg:fail.getMessage()});
      });
    });
  }

}
